﻿using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

using Common;
namespace Ym.print
{
    public partial class UsedEdit : PrintPageBase
    {
        public string color = "#ffffff";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (string.IsNullOrEmpty((string)Session["UserName"]))
                {
                    
                }
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    OleDbDataReader dr = OledbHelper.ExecuteReader("select * from P_Used where Id=" + Request.QueryString["id"].ToString());
                    if (dr.Read())
                    {
                        this.Text1.Value = dr["UName"].ToString();
                        this.TextArea1.Value = dr["UInfo"].ToString();
                        this.pUrl.Text = dr["UPic"].ToString();
                        color = dr["UColor"].ToString();
                        this.Hidden1.Value = dr["Id"].ToString();
                    }
                    ne.InnerText = "修改行业常用";
                    dr.Close();
                }
                else
                {
                    ne.InnerText = "添加行业常用";
                    Hidden1.Value = "0";
                }
            }
        }

        protected void save_Click(object sender, EventArgs e)
        {
            PBLL.PUsed bll = new PBLL.PUsed();
            PModel.PUsed model = new PModel.PUsed();

            model.UName = Text1.Value;
            model.UInfo = TextArea1.Value;
            model.UPic = pUrl.Text;
            model.UColor = col.Value;
            if (Hidden1.Value == "0")
            {
                bll.Insert(model);
                JscriptPrint("添加成功！", "Used.aspx", "Success");
            }
            else
            {
                model.Id = int.Parse(Hidden1.Value);
                bll.Update(model);
                JscriptPrint("修改成功！", "Used.aspx", "Success");
            }
        }
    }
}